<?php

class UserAction extends CommonAction {

    public function _initialize() {
        parent::_initialize();
    }

    /**
     * 会员列表
     */
    public function info() {
      if(!empty($_REQUEST)){
        $start_time = $_REQUEST['start_time'];
        $end_time   = $_REQUEST['end_time'];
        /*$start_time_tmp = $start_time?$start_time:date('Y/m/d',time()-30*24*60*60);
        $end_time_tmp = $end_time?$end_time:date('Y/m/d',time());*/
        
        $sql="select st_date,st_more from kp_user_all where timestamp(st_date) between '{$start_time}' and '{$end_time}'";
        }else{
            $sql="select st_date,st_more from kp_user_all";
        }
        $result=  mysql_query($sql);
        $a = array();
        $c=array();
        while($row = mysql_fetch_row($result)){
                $a[]= $row[1];
                $c[]=$row[0];
        }
         $b=  implode(',', $a);
         $str='';
         foreach($c as $v){
            $str.="'".$v."',";
         }
        $c=rtrim($str,',');
        $this->assign('b', $b);
        $this->assign('c', $c);
        $this->display();
    }
    public function daily_increased() {
        if(!empty($_REQUEST)){
            $start_time = $_REQUEST['start_time'];
            $end_time   = $_REQUEST['end_time'];
            $end_time_tmp = $end_time?$end_time:time();
            $sql="select * from kp_daily_increased where timestamp(st_date) between '{$start_time}' and '{$end_time}'";
        }else{
            $sql="select * from kp_daily_increased";
        }

        $result=  mysql_query($sql);
        $a = array();
        $c=array();
        while($row = mysql_fetch_row($result)){
                $a[]= $row[3];
                $c[]=$row[1];
        }

         $b=  implode(',', $a);
         $str='';
         foreach($c as $v){
            $str.="'".$v."',";
         }
        $c=rtrim($str,',');
       
        $this->assign('b', $b);
        $this->assign('c', $c);
        $this->display();
    }
    public function daily_active() {
       if(!empty($_REQUEST)){
            $start_time = $_REQUEST['start_time'];
            $end_time   = $_REQUEST['end_time'];
            $end_time_tmp = $end_time?$end_time:time();
            $sql="select * from kp_daily_active where timestamp(st_date) between '{$start_time}' and '{$end_time}'";
        }else{
            $sql="select * from kp_daily_active";
        }

        $result=  mysql_query($sql);
        $a = array();
        $c=array();
        while($row = mysql_fetch_row($result)){
                $a[]= $row[3];
                $c[]=$row[1];
        }

         $b=  implode(',', $a);
         $str='';
         foreach($c as $v){
            $str.="'".$v."',";
         }
        $c=rtrim($str,',');
       
        $this->assign('b', $b);
        $this->assign('c', $c);
        $this->display();
    }
    public function user_list(){
        //按照时间搜索
        if (!empty($_GET['start_time']) && !empty($_GET['end_time'])) {
            $start_time = strtotime($_GET['start_time']);
            $end_time = strtotime($_GET['end_time']);
            $end_time = $end_time + 60 * 60 * 24 - 1;
            $where['add_time'] = array('BETWEEN', "$start_time,$end_time");
            $title.= date('Y-m-d',$start_time).'至'.date('Y-m-d').' ';
        }
        //分页
        $count =M('user')->where($where)->count();
        $p = intval($_GET['p']) ? intval($_GET['p']) : 0;
	$num = 15;
        $this->_page($count, $num);
	$limit = $p.','.$num;
        
        $order = 'id desc';                        
        if (! empty($_GET['order'])) {
            $order = $_GET['order'] . ' desc';
        }
        
        $data=M('user')->where($where)->order($order)->page($limit)->select();
        $this->assign('data',$data);
        $this->display();
    }
    public function del()
    {
	$id = I('get.id');
	$model = M('user');
	// 从数据库中把记录删除掉
	// 返回值：如果失败返回FALSE，如果成功返回影响的条数
	if($model->delete($id) !== FALSE)
	{
	 $this->success('删除成功！');
	 exit;
	}
	 $this->error($model->getError());
	}
}
